$(function () {
    var options = {
        modalName: "权限",
        url: "/render/roleuserManager/list",
        getInfoUrl: "/render/roleuserManager/get/{id}",
        updateUrl: "/render/roleuserManager/edit",
        removeUrl: "/render/roleuserManager/remove",
        createUrl: "/render/roleuserManager/add",
        searchUrl: "/render/roleuserManager/search",
        pageNumber:1,
        pageSize:7,
        columns: [
            {
                checkbox: true,
                formatter:checkboxMatter
            }, {
                field: 'id',
                title: 'ID',
                align: "center",
                width: '50px',
                class:"colStyle",
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'iuser_id',
                title: '用户id',
                align: "center",
                width: '140px',
                sortable : true,
                cellStyle:formatTableUnit,
                formatter:paramsMatter
            }, {
                field: 'irole_id',
                title: '角色id',
                align: "center",
                width: '60px',
                sortable : true,
                cellStyle:formatTableUnit,
                // formatter:paramsMatter
                formatter: function (value) {

                    if (value == 1) {
                        value='管理员';
                    }

                    if (value == 2) {
                        value='店长';
                    }

                    if (value == 3) {
                        value='店员';
                    }

                    if (value == 4) {
                        value='普通用户';
                    }

                    // value = (value==1) ? '上架' : '下架';
                    var span=document.createElement('span');
                    span.setAttribute('title',value);
                    span.innerHTML = value;
                    return span.outerHTML;
                }
            }, {
                field: 'operate',
                title: '操作',
                align: "center",
                width: '100px',
                formatter: operateFormatter //自定义方法，添加操作按钮
            }
        ]
    };
    // 初始化table组件
    var table = new Table(options);
    table.init();

    //search按钮绑定查询事件
    $('#btnSearch').on('click', function () {
        var searchtext = {
            id: $("#search-id").val(),
            iuser_id: $("#search-iuser_id").val(),
            irole_id: $("#search-irole_id").val()
        };
        // console.log(""+$("#search-name").val());
        if($("#search-user_id").val() === ""&&$("#search-order_no").val() === ""&&$("#search-status").val() === ""){
            postParams(options.url,options.onExpandRow,options,options.rowStyle,options.columns,null,true);
        }else {
            postParams(options.searchUrl,options.onExpandRow,options,options.rowStyle,options.columns,JSON.stringify(searchtext),false);
        }
    });

    $(".close,.btn-default").on("click",function () {
        $(".modal").css("display","");
        $(".modal").removeClass("in");
        $(".modal-backdrop").removeClass("in");
    });
});
